﻿// Decompiled with JetBrains decompiler
// Type: Microsoft.InfoCards.TokenFactoryCredential
// Assembly: infocard, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// MVID: 8E14765A-6610-409A-BA36-099A0642905D
// Assembly location: E:\git\ALLIDA\windll\infocard.exe

using Microsoft.InfoCards.Diagnostics;
using System;
using System.IO;

namespace Microsoft.InfoCards
{
  internal abstract class TokenFactoryCredential : IDisposable
  {
    public const int NoCredential = -1;
    private TokenFactoryCredentialType m_type;
    private Uri m_cardId;
    private int m_paramIndex;
    private int m_lcid;

    protected TokenFactoryCredential(TokenFactoryCredentialType type)
    {
      this.m_type = type;
    }

    public void Dispose()
    {
      this.Dispose(true);
    }

    public virtual void Dispose(bool disposing)
    {
    }

    public static TokenFactoryCredential CreateFrom(
      BinaryReader reader,
      UIAgentRequest request,
      int lcid)
    {
      TokenFactoryCredential factoryCredential;
      switch (reader.ReadInt32())
      {
        case -1:
          factoryCredential = (TokenFactoryCredential) null;
          break;
        case 1:
          factoryCredential = (TokenFactoryCredential) new UserNameTokenFactoryCredential();
          factoryCredential.Deserialize(reader);
          break;
        case 2:
          factoryCredential = (TokenFactoryCredential) new SelfIssuedTokenFactoryCredential();
          factoryCredential.Deserialize(reader);
          break;
        case 3:
          factoryCredential = (TokenFactoryCredential) new X509CertificateTokenFactoryCredential(request);
          factoryCredential.Deserialize(reader);
          break;
        case 4:
          factoryCredential = (TokenFactoryCredential) new KerberosTokenFactoryCredential();
          factoryCredential.Deserialize(reader);
          break;
        default:
          InfoCardTrace.ThrowInvalidArgumentConditional(true, "CredentialType");
          factoryCredential = (TokenFactoryCredential) null;
          break;
      }
      if (factoryCredential != null)
        factoryCredential.LCID = lcid;
      return factoryCredential;
    }

    public int ParameterIndex
    {
      get
      {
        return this.m_paramIndex;
      }
    }

    public TokenFactoryCredentialType CredentialType
    {
      get
      {
        return this.m_type;
      }
    }

    public int LCID
    {
      get
      {
        return this.m_lcid;
      }
      set
      {
        this.m_lcid = value;
      }
    }

    public Uri CardId
    {
      get
      {
        return this.m_cardId;
      }
    }

    private void Deserialize(BinaryReader reader)
    {
      this.m_cardId = new Uri(Utility.DeserializeString(reader));
      this.m_paramIndex = reader.ReadInt32();
      this.DeserializeData(reader);
    }

    protected abstract void DeserializeData(BinaryReader reader);
  }
}
